package com.dg.lecheng.manager.controller;


import com.dg.lecheng.base.core.model.BaseResult;
import com.dg.lecheng.base.core.web.BaseController;
import com.dg.lecheng.api.user.service.InfoUserAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/10/22 0022.
 */
@Api(value = "InfoUserAuthController" ,description = "用户资源Controller")
@Controller
@RequestMapping("/infoUserAuth")
public class InfoUserAuthController extends BaseController{

    @Autowired
    private InfoUserAuthService infoUserAuthService;

    @ApiOperation("为用户授予角色资源")
    @RequestMapping(value = "/addRoleAuth" ,method = RequestMethod.POST)
    @ResponseBody
    public Object addAuthForRole(@ApiParam(name = "map",value = "用户角色资源集合") @RequestBody Map map){
        if(map == null)
            return BaseResult.fail(null);
        infoUserAuthService.saveRoleAuth(map);
        return BaseResult.success(null);
    }

    @ApiOperation("获取用户所有资源")
    @RequestMapping(value = "/getUserAuthByUserName" ,method = RequestMethod.GET)
    @ResponseBody
    public Object getUserAuthByUserName(@ApiParam(name = "userName",value = "登陆用户名")@RequestParam("userName") String userName){
        List<Map> list = infoUserAuthService.getUserAuthByUserName(userName);
        return BaseResult.success(list);
    }

}
